﻿// ===============================================================================
// XCI.WinForm.Platform 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using System.ComponentModel;
using DevExpress.XtraEditors.ViewInfo;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Drawing;
using System.Drawing;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Registrator;

namespace XCI.Windows
{
    /// <summary>
    /// 下拉多选控件
    /// </summary>
    [System.ComponentModel.DesignerCategory("Code")]
    public class CheckedComboBoxEditx : CheckedComboBoxEdit
    {
        static CheckedComboBoxEditx()
        {
            RepositoryItemCheckedComboBoxEditx.RegisterCheckedComboBoxEditx();
        }

        public CheckedComboBoxEditx()
        {

        }

        /// <summary>
        /// 获取或设置指定当前选定值。
        /// </summary>
        [Category("Data"), Description("获取或设置指定当前选定值。")]
        [Bindable(true)][DefaultValue(null)]
        public new object EditValue
        {
            get { return base.EditValue; }
            set
            {
                base.EditValue = value;
                if (base.Properties.DataSource != null)
                {
                    base.SetEditValue(value);
                }
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public new RepositoryItemCheckedComboBoxEditx Properties => base.Properties as RepositoryItemCheckedComboBoxEditx;

        public override string EditorTypeName => RepositoryItemCheckedComboBoxEditx.CustomEditName;
    }

    [UserRepositoryItem("RegisterCheckedComboBoxEditx")]
    public class RepositoryItemCheckedComboBoxEditx : RepositoryItemCheckedComboBoxEdit
    {
        static RepositoryItemCheckedComboBoxEditx()
        {
            RegisterCheckedComboBoxEditx();
        }

        public const string CustomEditName = "CheckedComboBoxEditx";

        public RepositoryItemCheckedComboBoxEditx()
        {
        }

        public override string EditorTypeName => CustomEditName;

        public static void RegisterCheckedComboBoxEditx()
        {
            Image img = null;
            EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(CustomEditName, typeof(CheckedComboBoxEditx), typeof(RepositoryItemCheckedComboBoxEditx), typeof(CheckedComboBoxEditxViewInfo), new CheckedComboBoxEditxPainter(), true, img));
        }

        public override void Assign(RepositoryItem item)
        {
            BeginUpdate();
            try
            {
                base.Assign(item);
                if (!(item is RepositoryItemCheckedComboBoxEditx source)) return;
                //
            }
            finally
            {
                EndUpdate();
            }
        }
    }


    public class CheckedComboBoxEditxViewInfo : PopupContainerEditViewInfo
    {
        public CheckedComboBoxEditxViewInfo(RepositoryItem item) : base(item)
        {
        }
    }

    public class CheckedComboBoxEditxPainter : ButtonEditPainter
    {
        public CheckedComboBoxEditxPainter()
        {
        }
    }
}